package com.aerotechnic.test;

import java.util.ArrayList;
import java.util.List;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.aerotechnic.entities.MacroTache;
import com.aerotechnic.entities.MacroTacheBiblio;
import com.aerotechnic.entities.Specialite;
import com.aerotechnic.service.interfaces.MacroTacheBiblioBoIn;
import com.aerotechnic.service.interfaces.SpecialiteBoIn;

public class initMacsHoldingDRF {

	private static ApplicationContext appContext = new ClassPathXmlApplicationContext(
			"spring/config/BeanLocations.xml");

	public static void main(String[] args) {
		// TODO Auto-generated method stub
//
		MacroTacheBiblioBoIn macBo = (MacroTacheBiblioBoIn) appContext
				.getBean("MacroTacheBiblioBo");
		SpecialiteBoIn specBo = (SpecialiteBoIn) appContext
				.getBean("SpecialiteBo");
		List<Specialite> specs = specBo.findAll();
		System.out.println("specs ==> " + specs);
		MacroTacheBiblio macHoldingDRF = null;

		// macroTache de la specialite B1
		macHoldingDRF = new MacroTacheBiblio();
		macHoldingDRF.setSpecialite(specs.get(0));
		macHoldingDRF.setIsSMOHolder(false);
		macHoldingDRF.setIntitule("traitement des DRF B1");
		macBo.save(macHoldingDRF);
//
		// macroTache de la specialite B2
		macHoldingDRF = new MacroTacheBiblio();
		macHoldingDRF.setSpecialite(specs.get(1));
		macHoldingDRF.setIsSMOHolder(false);
		macHoldingDRF.setIntitule("traitement des DRF B2");
		macBo.save(macHoldingDRF);

		// macroTache de la specialite B3
		macHoldingDRF = new MacroTacheBiblio();
		macHoldingDRF.setSpecialite(specs.get(2));
		macHoldingDRF.setIsSMOHolder(false);
		macHoldingDRF.setIntitule("traitement des DRF B3");
		macBo.save(macHoldingDRF);
		
		// macroTache de la specialite B3
		macHoldingDRF = new MacroTacheBiblio();
		macHoldingDRF.setSpecialite(specs.get(3));
		macHoldingDRF.setIsSMOHolder(false);
		macHoldingDRF.setIntitule("traitement des DRF MC");
		macBo.save(macHoldingDRF);
		
//		List<MacroTacheBiblio> macsBib = macBo.findAll();
//		for(MacroTacheBiblio macBic:macsBib){
//			if(macBic.getIsSMOHolder()==null){
//				System.out.println("macBib ===> "+macBic);
//				macBic.setIsSMOHolder(true);
//				macBo.update(macBic);
//			}
//		}
//		macsBib = macBo.findAll();
//		
//		System.out.println("macs array after update : "+macsBib);
	}

}
